<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('物品列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>项目：</label>
                            <!--                                <input type="text" name="projectId"/>-->
                            <select id="projectId" name="projectId">
                                <!--                                    <option value="">所有</option>-->
                                <option th:each="item:${@erpService.selectErpProjectList()}"
                                        th:text="${item.projectName}"
                                        th:value="${item.projectId}"></option>
                                <option value="">所有</option>
                            </select>
                        </li>
                        <li>
                            <label>物品名：</label>
                            <input type="text" name="goodName"/>
                        </li>
                        <li>
                            <label>物品编码：</label>
                            <input type="text" name="goodsId"/>
                        </li>

                        <!--                            <li>-->
                        <!--                                <label>父节点：</label>-->
                        <!--                                <input type="text" name="parentId"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>父节点名称：</label>-->
                        <!--                                <input type="text" name="parentName"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>提醒：</label>-->
                        <!--                                <input type="text" name="attention"/>-->
                        <!--                            </li>-->

                        <!--                            <li>-->
                        <!--                                <label>项目名：</label>-->
                        <!--                                <input type="text" name="projectName"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>总数：</label>-->
                        <!--                                <input type="text" name="totalNumber"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>材质：</label>-->
                        <!--                                <input type="text" name="goodsMaterial"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>单重：</label>-->
                        <!--                                <input type="text" name="itemWeight"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>总重：</label>-->
                        <!--                                <input type="text" name="totalWeight"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>单价：</label>-->
                        <!--                                <input type="text" name="itemPrice"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>总价：</label>-->
                        <!--                                <input type="text" name="totalPrice"/>-->
                        <!--                            </li>-->
                        <li>
                            <label>供货商：</label>
                            <input type="text" name="supplierName"/>
                        </li>
                        <!--                            <li>-->
                        <!--                                <label>采购数：</label>-->
                        <!--                                <input type="text" name="purchasesNum"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>采购数绑定员工：</label>-->
                        <!--                                <input type="text" name="purchasesNumMemberId"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>质检数：</label>-->
                        <!--                                <input type="text" name="inspectionNum"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>质检数绑定员工：</label>-->
                        <!--                                <input type="text" name="inspectionNumMemberId"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>入库数：</label>-->
                        <!--                                <input type="text" name="stockNum"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>入库数绑定员工：</label>-->
                        <!--                                <input type="text" name="stockNumMemberId"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>出库数：</label>-->
                        <!--                                <input type="text" name="outboundNum"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>出库数绑定员工：</label>-->
                        <!--                                <input type="text" name="outboundNumMemberId"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>图片备注：</label>-->
                        <!--                                <input type="text" name="pictureRemark"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>视频备注：</label>-->
                        <!--                                <input type="text" name="videoRemark"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>质检员：</label>-->
                        <!--                                <input type="text" name="qualityInspectorName"/>-->
                        <!--                            </li>-->
                        <!--                            <li>-->
                        <!--                                <label>质检时间：</label>-->
                        <!--                                <input type="text" class="time-input" placeholder="请选择质检时间" name="qualityInspectorTime"/>-->
                        <!--                            </li>-->
                        <li>
                            <label>结果：</label>
                            <input type="text" name="result"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:goods:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="erp:goods:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="erp:goods:import">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-danger multiple " onclick="$.operate.removeAll()" shiro:hasPermission="erp:member:remove">
                <i class="fa fa-remove"></i> 删除
            </a>

            <a class="btn btn-danger multiple " onclick="removeAllByProjectId()" shiro:hasPermission="erp:member:remove">
                <i class="fa fa-remove"></i> 清空
            </a>

            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:goods:export">
                <i class="fa fa-download"></i> 导出
            </a>

            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-tree-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('erp:goods:add')}]];
    var editFlag = [[${@permission.hasPermi('erp:goods:edit')}]];
    var removeFlag = [[${@permission.hasPermi('erp:goods:remove')}]];
    var prefix = ctx + "erp/goods";
    $(function () {

        var options = {
            code: "goodsId",
            parentCode: "parentId",
            expandColumn: "1",
            uniqueId: "goodsId",
            ajaxParams: {
                "projectId": $("#projectId").val()
            },
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            removeAllUrl: prefix + "/remove",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            exportUrl: prefix + "/export",
            modalName: "物品",
            columns: [{
                field: 'selectItem',
                checkbox: true
            },
                {
                    field: 'goodName',
                    title: '物品名',
                    align: 'left'
                },
                {
                    field: 'goodsId',
                    title: '物品编码',
                    align: 'left'
                },
                {
                    field: 'parentId',
                    title: '父节点',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'parentName',
                    title: '父节点名称',
                    align: 'left'
                },
                {
                    field: 'attention',
                    title: '提醒',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'projectId',
                    title: '项目',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'projectName',
                    title: '项目名',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'totalNumber',
                    title: '总数',
                    align: 'left'
                },
                {
                    field: 'goodsMaterial',
                    title: '材质',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'itemWeight',
                    title: '单重',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'totalWeight',
                    title: '总重',
                    align: 'left'
                },
                {
                    field: 'itemPrice',
                    title: '单价',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'totalPrice',
                    title: '总价',
                    align: 'left'
                },
                {
                    field: 'supplierName',
                    title: '供货商名称',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'purchasesNum',
                    title: '采购数',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'purchasesNumMemberId',
                    title: '采购数绑定员工',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'inspectionNum',
                    title: '质检数',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'inspectionNumMemberId',
                    title: '质检数绑定员工',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'stockNum',
                    title: '入库数',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'stockNumMemberId',
                    title: '入库数绑定员工',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'outboundNum',
                    title: '出库数',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'outboundNumMemberId',
                    title: '出库数绑定员工',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'pictureUrl',
                    title: '多图',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'pictureRemark',
                    title: '图片备注',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'videoUrl',
                    title: '视频',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'videoRemark',
                    title: '视频备注',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'qualityInspectorName',
                    title: '质检员',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'qualityInspectorTime',
                    title: '质检时间',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'result',
                    title: '结果',
                    align: 'left',
                    visible: false
                },
                {
                    field: 'remark',
                    title: '备注',
                    align: 'left',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.goodsId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodsId + '\')"><i class="fa fa-plus"></i>新增</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodsId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.treeTable.init(options);
    });

    function removeAllByProjectId() {
       var projectId  =  $("#projectId").val();

        if (projectId ==null||projectId==undefined||projectId=="" ) {
            $.modal.alertWarning("请选择项目");
            return;
        }
        $.modal.confirm("确认要删除:<<" +  $("#projectId").find("option:selected").text()   + ">>项目中的所有数据吗?", function () {
            var url = table.options.removeAllUrl;
            $.ajax({
                type: "get",
                url:  "/erp/goods/removeAllByProjectId/"+projectId,

                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    debugger
                    if (result.code == web_status.SUCCESS) {
                        $.modal.closeAll();
                        $.modal.alertSuccess(result.msg);
                        $.treeTable.refresh();
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("删除失败。");
                }
            });



        });
    }


</script>
</body>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <!--                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据-->
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>

</html>